//
//  LRXAccpetOrderView.m
//  路人侠
//
//  Created by zhangxulong on 4/20/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXAccpetOrderView.h"
#import "LRXHelpMoreInfoCell.h"
@interface LRXAccpetOrderView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,weak) LRXHelpMeInfoModel * model;
@end
@implementation LRXAccpetOrderView
- (instancetype)initAccpetOrder:(LRXHelpMeInfoModel *)accpetOder
{
    if (self = [super init]) {
        self.model = accpetOder;
        self.backgroundColor = [UIColor whiteColor];
        UIView * headView = [[UIView alloc]init];
        headView.frame = CGRectMake(0, 0, 545 * wScale, 163 * hScale);
        headView.backgroundColor = mainColor;
        UIImageView * userIconImage = [[UIImageView alloc]init];
        [userIconImage sd_setImageWithURL:[NSURL URLWithString:accpetOder.userIcon] placeholderImage:[UIImage imageNamed:@"de"]];
        userIconImage.frame = CGRectMake(65 * wScale, 31 * hScale, 106 * hScale, 106 * hScale);
        userIconImage.layer.cornerRadius = userIconImage.frame.size.height * 0.5;
        userIconImage.layer.masksToBounds = YES;
        
        UILabel * sumMoney = [[UILabel alloc]init];
        sumMoney.text = [NSString stringWithFormat:@"总价： %@元",accpetOder.allMoney];
        sumMoney.textColor = [UIColor whiteColor];
        sumMoney.font = [UIFont systemFontOfSize:28 * hScale];
        UILabel * tipMoney = [[UILabel alloc]init];
        tipMoney.text = [NSString stringWithFormat:@"已含小费%@元",accpetOder.tip];
        tipMoney.textColor = [UIColor whiteColor];
        tipMoney.font = [UIFont systemFontOfSize:28 * hScale];
        sumMoney.frame = CGRectMake(293 * wScale, 38 * hScale, 0, 0);
        tipMoney.frame = CGRectMake(293 * wScale, 100 * hScale, 0, 0);
        [sumMoney sizeToFit];
        [tipMoney sizeToFit];
        [headView addSubview:userIconImage];
        [headView addSubview:sumMoney];
        [headView addSubview:tipMoney];
        [self addSubview:headView];
        
//        CGFloat tableViewH = accpetOder.thingArray.count * 85 * hScale;
        UITableView * tableView = [[UITableView alloc]init];
        tableView.backgroundColor = [UIColor whiteColor];
        tableView.frame = CGRectMake(90 * wScale, CGRectGetMaxY(headView.frame) + 50 * hScale, 545 * wScale - 180 * wScale, 450 * hScale);
        tableView.delegate = self;
        tableView.dataSource= self;
        tableView.rowHeight = 60 * hScale;
        tableView.showsVerticalScrollIndicator = NO;
        tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        
        self.orderViewH =  CGRectGetMaxY(tableView.frame);
        [self addSubview:tableView];
        
        
        
    }
    return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * helpMoreReUsedID = @"helpMoreReUsedID";
    LRXHelpMoreInfoCell * cell = [tableView dequeueReusableCellWithIdentifier:helpMoreReUsedID];
    if (cell == nil) {
        cell = [[LRXHelpMoreInfoCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:helpMoreReUsedID];
    }
    //没有边界
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    LRXThing * thing = self.model.thingArray[indexPath.row];
    [cell layoutHelpMoreCell:thing];
    
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.model.thingArray.count;
}
+ (instancetype)accpetOrderWithModel:(LRXHelpMeInfoModel *)accpetOder
{
    return [[LRXAccpetOrderView alloc]initAccpetOrder:accpetOder];
}
@end
